package com.quartet.utils;

import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.google.common.collect.Lists;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 邮件服务
 */
@Log4j2
@Component
public class EmailUtil {

	@Value("${emailHost}")
	private String emailHost;

	@Value("${emailPort}")
	private Integer emailPort;

	@Value("${emailFrom}")
	private String emailFrom;

	@Value("${emailUser}")
	private String emailUser;

	@Value("${emailPass}")
	private String emailPass;


	/**
	 * 向指定手机发送信息
	 * 暂时只存在验证码模板（只能发验证码）
	 */
	public void sendMail(String email,String emailSubject,String emailContent){
		MailAccount account = new MailAccount();
		account.setHost(emailHost);
		account.setPort(emailPort);
		account.setAuth(true);
		account.setFrom(emailFrom);
		account.setUser(emailUser);
		account.setPass(emailPass);
		MailUtil.send(account, Lists.newArrayList(email), emailSubject, emailContent, false);
	}
}



